package com.coscoshipping.rams.demo.controller;

import com.coscoshipping.rams.demo.entity.BlockAnalysis;
import com.coscoshipping.rams.demo.pojo.dto.GroupInfoDTO;
import com.coscoshipping.rams.demo.pojo.dto.GroupToBlockDTO;
import com.coscoshipping.rams.demo.service.IBlockHeaderService;
import com.coscoshipping.rams.utils.base.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaoyin.yang
 * @since 2025-01-15
 */
@Slf4j
@Tag(name = "预控分析表")
@Validated
@RestController
@RequestMapping("/blockAnalysis")
public class BlockAnalysisController {


    @Autowired
    private IBlockHeaderService blockHeaderService;


    @ApiOperationSupport(order = 1)
    @Operation(summary = "根据blockname查询block")
    @PostMapping("/getBlockHeaderList")
    public Result<List<BlockAnalysis>> getBlockHeaderList(@RequestParam("blockname")String blockname){
        return Result.data(blockHeaderService.getBlockHeaderList(blockname));
    }



    @ApiOperationSupport(order = 2)
    @Operation(summary = "团队主单关联Block")
    @PostMapping("/connectGroupToBlock")
    public Result connectGroupToBlock(@RequestBody GroupToBlockDTO groupToBlockDTO){
        blockHeaderService.connectGroupToBlock(groupToBlockDTO);
        return Result.success();
    }



    @ApiOperationSupport(order = 3)
    @Operation(summary = "查询指定block的团队列表")
    @PostMapping("/getGroupByBlockcode")
    public Result<List<GroupInfoDTO>> getGroupByBlockcode(@RequestParam(name = "blockcode")
                                      @NotBlank(message="blockcode不能为空")
                                      String blockcode){
        return Result.data(blockHeaderService.getGroupByBlockcode(blockcode));
    }




    @ApiOperationSupport(order = 4)
    @Operation(summary = "获取指定团队主单的收入信息、支付信息")
    @PostMapping("/getGroupInfo")
    public Result<GroupInfoDTO> getGroupInfo(@RequestParam(name = "groupno")
                                             @NotBlank(message="groupno不能为空")
                                             String groupno){
        return Result.data(blockHeaderService.getGroupInfo(groupno));
    }


    @ApiOperationSupport(order = 5)
    @Operation(summary = "获取指定block的收入信息、支付信息")
    @PostMapping("/getBlockInfo")
    public Result<List<GroupInfoDTO>> getBlockInfo(@RequestParam(name = "blockcode")
                                                  @NotBlank(message="blockcode不能为空")
                                                  String blockcode){
        return Result.data(blockHeaderService.getBlockInfo(blockcode));
    }
}
